#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
using namespace std;


class Solution {
public:
    int maximumProduct(vector<int>& nums) {
        sort(nums.begin(),nums.end());
        int index = 0;
        for(int i =0 ;i<nums.size();++i){
            if(nums[i]>=0){
                index = i;
                break;
            }
        }
        int result1 = INT32_MIN;
        if(index>=1&&nums.size()-1-index>=0){
            int a = nums[0];
            int b = nums[1];
            int c = nums[nums.size()-1];
            result1 = a*b*c;
            
        }
        int result2 = 1;
        int size = nums.size();
        for(int i = (size-1);i>=(size-3);--i){
            result2 = result2*nums[i];
        }
        return max(result1,result2);
    }
};

int main(){
    Solution S;
    vector<int> nums = {-100,-98,-1,1,2,3,4};
    cout<<S.maximumProduct(nums)<<endl;
}